<?php
function buttonAction($act,$text,$linkend='')
{
    global $module;
    if($act=="delete" || $act=="delcontent")
    {
        $ask='if(confirm(\''.getLang('Do you want delete').'?\'))';
    }
    $html = '<input type="button" class="b1"';
    $html.= ' onclick="'.$ask.' location=\'?module='.$module.'&opt='.$act.'&'.$linkend.'\'" value="'.$text.'"/>';
    return $html;
}
function linkAction($act,$text,$linkend='')
{
    global $module,$child;
    $ask    = '';
    if(strpos($act,"del")!==false)
    {
        $ask='if(confirm(\''.getLang('Do you want delete').'?\'))';
    }
    $link   = '?module='.$module.'&opt='.$act.'&'.$linkend;
    if(!empty($child))
    {
        $link.='&child='.$child;
    }
    $link='<a href="#" onclick="'.$ask.' location=\''.$link.'\'">'.$text.'</a>';
    return $link;
}

function openPopup($url,$text,$w,$h)
{
    $link='<a href="#" onclick="openPI(\'Map\',\''.$url.'\','.$w.','.$h.')">'.$text.'</a>';
    return $link;
}
function selectAction($name,$linkend='')
{
    global $module;
    $link="location='?module=".$module."&$name='+this.value+'".$linkend."'";
    return $link;
}

function formAction($act,$linkend='')
{
    global $module,$child;
    $link   = '?module='.$module;
    if(!empty($child))
    {
        $link   .= '&child='.$child;
    }
    $link  .= '&opt='.$act.'&'.$linkend;
    return $link;
}
function formEditAction($linkend='')
{
    global $module,$act,$child;
    $actF   = str_replace(array("add","edit"),array("insert","update"),$act);
    if($act=="myaccount" || $act=="index")
    {
        $actF="update";
    }
    $link='?module='.$module.'&opt='.$actF.'&'.$linkend;
    if(!empty($child))
    {
        $link.='&child='.$child;
    }
    return $link;
}

function inputDate($name,$value,$format='yyyy/mm/dd')
{
    if($value=="0000-00-00")
    {
        $value="";
    }
    $html='<input name="'.$name.'" type="text" id="'.$name.'" class="date" size="10" value="'.$value.'"
            readonly=""  onfocus="displayCalendar(this,\''.$format.'\',this)"/>
        	<img src="images/cal.gif" title="Select date" border="0"
			onclick="displayCalendar(document.getElementById(\''.$name.'\'),\''.$format.'\',this)" ';
    return $html;
}
function inputCheckAll($name='cid')
{
    return '<input type="checkbox" onclick="checkall(this,\''.$name.'\')" />';
}
function inputCheck($id,$name='cid',$val='')
{
    $html='<input type="checkbox" name="'.$name.'[]" class="'.$name.'" value="'.$id.'" ';
    if($id==$val)
    {
        $html .= ' checked ';
    }
    $html  .= '/>';
    return $html;
}

function CheckBoolean($name,$val=0,$isList=false)
{
    global $countcheckbox;
    $count  = isset($countcheckbox[$name]) ? $countcheckbox[$name] : 0; 
    $countcheckbox[$name]= intval($countcheckbox[$name])+1;
    $html='<input type="checkbox" name="'.$name.($isList? '['.$count.']': '').'" class="'.$name.'" id="'.$name.'"  value="1" ';
    if($val ==1)
    {
        $html .= ' checked ';
    }
    $html  .= '/>';
    return $html;
}
function buttonResetPage($id=0)
{
    global $module,$page,$act;
    $html='<input type="button" value="reset" onclick="location=\'?module='.$module;
    if($page>0)
    {
        $html.='&page='.$page;
    }
    if($act!="index")
    {
        $html.='&opt='.$act;
    }
    if($id>0)
    {
        $html.="&id=$id";
    }
    $html.='\'">';
    return $html;
}
function inputSearch($dftext)
{
    global $search;
    if(!empty($search))
    {
        $dftext=$search;
    }
    $url=$_SERVER['REQUEST_URI'];
    $url=preg_replace("((&search=)([^\&]*))","",$url);
    $html='<input type="text" class="short" id="search" value="'.$dftext.'" onkeypress="if(event.keyCode==13)search_click()"';
    $html.=' onfocus="this.value=\'\'" onblur="if(this.value==\'\')this.value=\''.$dftext.'\'" />&nbsp;';
    $html.='<input type="button" value='.Search.' onclick="search_click()">';
    $html.='<script>function search_click(){if(getId(\'search\').value!=\''.$dftext.'\')location=\''.$url.'&search=\'+getId(\'search\').value}</script>';
    return $html;
}

function inputFile($name,$value='',$folderdf='',$readonly=true)
{
    global $folder_img_upload;
    $folder     = "../".$folder_img_upload;
    $readonly   = ($readonly===true)? 'readonly="true"' : '';
    $html = '<input type="text" '.$readonly.' id="'.$name.'" name="'.$name.'" class="normal0" value="'.$value.'" />';
    $html.= '<script>uploadImg("'.$name.'","'.$folder.'","'.$value.'","'.$folderdf.'")</script>';
    return $html;
}

function CheckBox($name,$vl,$text)
{
    $html   = '<input type="checkbox" name="'.$name.'" value="1" '.(($vl!=false)? "checked": "").'> '.$text;
    return $html;
}
?>